using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class SpecialBll
	{
		private Conn conn = null;
		public SpecialBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public SpecialBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetAllSpcilaid()
		{
			return this.conn.GetDataTable("SELECT * From [HL_Special] Order By SpecialID Desc");
		}
		public DataTable GetAllSpcilNameID()
		{
			return this.conn.GetDataTable("SELECT SpecialID, ChannelID, SpecialName, SkinID From [HL_Special] Order By SpecialID Desc");
		}
		public bool UpdateSpecial(int OpenType, int SkinID, string Template, int MaxPerPage, bool IsElite, string SpecialIDs)
		{
			return true;
		}
		public bool UpdateSpecial(string Custom_Content, bool IsElite, bool IsVisible, int ChannelID, int OpenType, string Tips, string ReadMe, int SkinID, string SpecialDir, string SpecialName, string SpecialPicUrl, string Template, int MaxPerPage, int SpecialID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@ChannelID", DbType.Int32, ChannelID),
				this.conn.CreateParameter("@SpecialName", DbType.String, SpecialName),
				this.conn.CreateParameter("@OpenType", DbType.Int32, OpenType),
				this.conn.CreateParameter("@SpecialPicUrl", DbType.String, SpecialPicUrl),
				this.conn.CreateParameter("@Tips", DbType.String, Tips),
				this.conn.CreateParameter("@ReadMe", DbType.String, ReadMe),
				this.conn.CreateParameter("@SkinID", DbType.Int32, SkinID),
				this.conn.CreateParameter("@Template", DbType.String, Template),
				this.conn.CreateParameter("@SpecialDir", DbType.String, SpecialDir),
				this.conn.CreateParameter("@MaxPerPage", DbType.Int32, MaxPerPage),
				this.conn.CreateParameter("@IsElite", DbType.Boolean, IsElite),
				this.conn.CreateParameter("@Custom_Content", DbType.String, Custom_Content),
				this.conn.CreateParameter("@IsVisible", DbType.Boolean, IsVisible),
				this.conn.CreateParameter("@Original_SpecialID", DbType.Int32, SpecialID)
			};
			return this.conn.Execute("UPDATE [HL_Special] SET [ChannelID] = @ChannelID, [SpecialName] = @SpecialName, [OpenType] = @OpenType, [SpecialPicUrl] = @SpecialPicUrl, [Tips] = @Tips, [ReadMe] = @ReadMe, [SkinID] = @SkinID, [Template] = @Template, [SpecialDir] = @SpecialDir, [MaxPerPage] = @MaxPerPage, [IsElite] = @IsElite, [Custom_Content] = @Custom_Content, [IsVisible] = @IsVisible WHERE (([SpecialID] = @Original_SpecialID))", parameters) >= 1;
		}
		public bool DeleteSpecial(int SpecialID)
		{
			return this.conn.Execute("DELETE From [HL_Special] Where SpecialID=" + SpecialID) >= 1;
		}
		public bool AddSpeial(string Custom_Content, bool IsElite, bool IsVisible, int ChannelID, int OpenType, string Tips, string ReadMe, int SkinID, string SpecialDir, string SpecialName, string SpecialPicUrl, string Template, int MaxPerPage, int OrderID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@ChannelID", DbType.Int32, ChannelID),
				this.conn.CreateParameter("@SpecialName", DbType.String, SpecialName),
				this.conn.CreateParameter("@OpenType", DbType.Int32, OpenType),
				this.conn.CreateParameter("@SpecialPicUrl", DbType.String, SpecialPicUrl),
				this.conn.CreateParameter("@OrderID", DbType.Int32, OrderID),
				this.conn.CreateParameter("@Tips", DbType.String, Tips),
				this.conn.CreateParameter("@ReadMe", DbType.String, ReadMe),
				this.conn.CreateParameter("@SkinID", DbType.Int32, SkinID),
				this.conn.CreateParameter("@Template", DbType.String, Template),
				this.conn.CreateParameter("@SpecialDir", DbType.String, SpecialDir),
				this.conn.CreateParameter("@MaxPerPage", DbType.Int32, MaxPerPage),
				this.conn.CreateParameter("@IsElite", DbType.Boolean, IsElite),
				this.conn.CreateParameter("@Custom_Content", DbType.String, Custom_Content),
				this.conn.CreateParameter("@IsVisible", DbType.Boolean, IsVisible)
			};
			return this.conn.Execute("INSERT INTO [HL_Special] ([ChannelID], [SpecialName], [OpenType], [SpecialPicUrl], [OrderID], [Tips], [ReadMe], [SkinID], [Template], [SpecialDir], [MaxPerPage], [IsElite], [Custom_Content], [IsVisible]) VALUES (@ChannelID, @SpecialName, @OpenType, @SpecialPicUrl, @OrderID, @Tips, @ReadMe, @SkinID, @Template, @SpecialDir, @MaxPerPage, @IsElite, @Custom_Content, @IsVisible)", parameters) >= 1;
		}
		public DataTable GetSpecialByID(int SpecialID)
		{
			return this.conn.GetDataTable("Select * From [HL_Special] Where SpecialID=" + SpecialID);
		}
		public DataTable GetSpecialByTemplate(string Template)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@Template", DbType.String, Template);
			return this.conn.GetDataTable("Select * From [HL_Special] Where ([Template] = @Template)", new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetSpecialBySkinID(int SkinID)
		{
			return this.conn.GetDataTable("Select * From [HL_Special] Where SkinID=" + SkinID);
		}
		public DataTable GetSpecialIsElite()
		{
			return this.conn.GetDataTable("Select * From [HL_Special] Where IsElite=1");
		}
		public bool GetSpcilaidByDir(string SpecialDir)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@SpecialDir", DbType.String, SpecialDir);
			return this.conn.ExecuteCount("Select count(SpecialID) From [HL_Special] Where ([SpecialDir] = @SpecialDir)", new IDbDataParameter[]
			{
				dbDataParameter
			}) >= 1;
		}
		public bool GetSpcilaidByDir(string SpecialDir, int SpecialID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@SpecialDir", DbType.String, SpecialDir);
			IDataReader reader = this.conn.GetReader("Select SpecialID From [HL_Special] Where ([SpecialDir] = @SpecialDir)", new IDbDataParameter[]
			{
				dbDataParameter
			});
			bool result;
			if (reader.Read())
			{
				if (Convert.ToInt32(reader["SpecialID"].ToString()) != SpecialID)
				{
					reader.Close();
					reader.Dispose();
					result = true;
				}
				else
				{
					reader.Close();
					reader.Dispose();
					result = false;
				}
			}
			else
			{
				reader.Close();
				reader.Dispose();
				result = false;
			}
			return result;
		}
		public bool isNameRepeat(string SpecialName)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@SpecialName", DbType.String, SpecialName);
			return this.conn.ExecuteCount("Select count(SpecialID) From [HL_Special] Where ([SpecialName] = @SpecialName)", new IDbDataParameter[]
			{
				dbDataParameter
			}) >= 1;
		}
		public bool isNameRepeat(string SpecialName, int SpecialID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@SpecialName", DbType.String, SpecialName);
			IDataReader reader = this.conn.GetReader("Select SpecialID From [HL_Special] Where ([SpecialName] = @SpecialName)", new IDbDataParameter[]
			{
				dbDataParameter
			});
			bool result;
			if (reader.Read())
			{
				if (Convert.ToInt32(reader["SpecialID"].ToString()) != SpecialID)
				{
					reader.Close();
					reader.Dispose();
					result = true;
				}
				else
				{
					reader.Close();
					reader.Dispose();
					result = false;
				}
			}
			else
			{
				reader.Close();
				reader.Dispose();
				result = false;
			}
			return result;
		}
	}
}
